package com.longai.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;


import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.longai.model.Enroll;
import com.longai.model.Event;
import com.longai.service.EnrollService;
import com.longai.service.EventService;
import com.longai.service.UserService;
import com.longai.vo.EnrollVo;


@Controller
@RequestMapping("enroll")

public class EnrollAction{
	
	@Autowired
	EnrollService enrollService;
	@Autowired
	UserService userService;
	@Autowired
	EventService eventService;

	@RequestMapping(value="enrollEvent",method = RequestMethod.GET)
	@ResponseBody
	public Object enrollEvent(@RequestParam(value="eventId") String eventId,
			@RequestParam(value="userId") String userId){
				try {
					EnrollVo vo=new EnrollVo();
					Enroll enroll=new Enroll();
					enroll.setUser(userService.findById(Integer.valueOf(userId)));
					enroll.setEvent(eventService.findById(Integer.valueOf(eventId)));
					enrollService.save(enroll);
					vo.setEnrollId(enroll.getEnrollId());
					vo.setEventId(Integer.valueOf(eventId));
					vo.setUserId(Integer.valueOf(userId));
					return vo;
				} catch (Exception e) {
					// TODO: handle exception
					Enroll enroll2=new Enroll();
					return enroll2;
				}		
		}
			
}
